@file:OptIn(ExperimentalMaterial3Api::class)

package com.example.cardiacmonitor

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.cardiacmonitor.ecg.RealTimePlotScreen
import com.example.cardiacmonitor.patient.PatientInfoScreen
import com.example.cardiacmonitor.report.ReportGeneratorScreen
import com.example.cardiacmonitor.ui.theme.CardiacmonitorTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            CardiacmonitorTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    MainNavigation()
                }
            }
        }
    }
}

@Composable
fun MainNavigation() {
    val navController = rememberNavController()
    NavHost(
        navController = navController,
        startDestination = "home"
    ) {
        composable("home") { AppHomeScreen(navController) }
        composable("patient") { PatientInfoScreen(navController) }
        composable("ecg") { RealTimePlotScreen(navController) }
        composable("report") { ReportGeneratorScreen(navController) }
    }
}

@Composable
fun AppHomeScreen(navController: NavHostController) {
    Scaffold(
        topBar = {
            TopAppBar(title = { Text("心脏监测系统") })
        }
    ) { innerPadding ->
        Column(
            modifier = Modifier
                .padding(innerPadding)
                .fillMaxSize(),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Button(
                onClick = { navController.navigate("patient") },
                modifier = Modifier
                    .padding(all = 16.dp)
                    .width(200.dp)
            ) {
                Text("患者信息管理")
            }

            Button(
                onClick = { navController.navigate("ecg") },
                modifier = Modifier
                    .padding(all = 16.dp)
                    .width(200.dp)
            ) {
                Text("实时心电图监测")
            }

            Button(
                onClick = { navController.navigate("report") },
                modifier = Modifier
                    .padding(all = 16.dp)
                    .width(200.dp)
            ) {
                Text("报告生成系统")
            }
        }
    }
}